home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3605 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  52 lines

  1. Newsgroups: comp.lang.c
  2. Path: gail.ripco.com!mambuhl
  3. From: mambuhl@ripco.com (Martin Ambuhl)
  4. Subject: Re: New C Programmer Has 
  5. X-Nntp-Posting-Host: golden.ripco.com
  6. Message-ID: <DLz0oJ.KJ6@rci.ripco.com>
  7. Sender: usenet@rci.ripco.com (Net News Admin)
  8. Organization: Ripco Internet BBS Chicago
  9. Date: Tue, 30 Jan 1996 01:41:07 GMT
  10. X-Ident-Sender: mambuhl
  11.  
  12. tsyslo@oasis.novia.net (Tony Syslo)
  13. in <4ehpa3$6kl@nntp.novia.net> asks:
  14.  
  15. >  I have a question on C... why isn't this program working?!
  16.  
  17. Because it isn't written in C.
  18.  
  19. Clean this up in several stages:
  20. 1) declare name with some space allocated to it, instead of an
  21.     uninitialized pointer.
  22. 2) lose the non-standard headers <clib/dos_protos.h>, <dos/dos.h>,
  23.     <exec/types.h>.  Learn to use the standard libraries.
  24. 3) lose the useless and wrong prototype of main
  25. 4) remember that main returns an int.  Declare it so.
  26. 5) rewrite the use of the non-standard functions (whatever they are)
  27.         Open()  /* use fopen() */
  28.         Close() /* use fclose() */
  29.         Write() /* use fwrite() */
  30.         Read()  /* use fread() */
  31.         Seek()  /* use fseek() */
  32.         Exit()  /* use exit() */
  33. 6) lose the non-standard struct FileHandle *.  The standard way to
  34.     access files is through FILE *s.
  35. 7) get the FAQ from rtfm.mit.edu and read it.  Pay attention to the
  36.     suggestions on alternatives to scanf() and gets().
  37. 8) don't assign strings to char *s in the body of the code.
  38. 9) don't use non-terminated strings as in:
  39.       printf("Hello, %s!\",name);
  40.  
  41. >  Also, is there any of you whom might have a routine to figure up random (or
  42. >  even psuedo-random) numbers?? Some algorithm, or such, as I need one BADLY!!
  43.  
  44. 10) Try using the standard functions rand() and srand().  Once again,
  45.     the FAQ will be of use.  Why are you using all this non-standard
  46.     crap when you don't seem to have a clue what the standard libraries
  47.     contain?
  48.                                                                                                                           
  49. --
  50. * Martin Ambuhl       net: mambuhl@ripco.com
  51. * Chicago, IL (USA)    
  52.